package com.fqy.gmall.product.controller;

import com.fqy.gmall.common.result.Result;
import com.fqy.gmall.model.product.BaseTrademark;
import com.fqy.gmall.model.product.CategoryTrademarkVo;
import com.fqy.gmall.product.service.BaseCategoryTrademarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * User: fqy
 * Date: 2021/9/11
 * Time: 11:43
 * Describe: 分类品牌管理
 */
@Api(tags = "分类品牌管理：分类品牌接口")
@RestController
@RequestMapping("admin/product/baseCategoryTrademark/")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    //admin/product/baseCategoryTrademark/findTrademarkList/{category3Id}
    @ApiOperation("根据category3Id获取品牌列表")
    @GetMapping("findTrademarkList/{category3Id}")
    public Result findTrademarkList(@PathVariable Long category3Id){
        //根据category3Id获取品牌列表
//        select * from base_category_trademark where category3_id = 61;
//        select * from base_trademark where id in (1,3);
        List<BaseTrademark> trademarkList =  baseCategoryTrademarkService.findTrademarkList(category3Id);
        return Result.ok(trademarkList);
    }
    //  根据分类Id 获取可选的品牌数据
    //  /admin/product/baseCategoryTrademark/findCurrentTrademarkList/{category3Id}
    @ApiOperation("根据category3Id 获取可选的品牌数据")
    @GetMapping("findCurrentTrademarkList/{category3Id}")
    public Result findCurrentTrademarkList(@PathVariable Long category3Id){
        //  调用服务层方法
        List<BaseTrademark> baseTrademarkList = baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);
    }

    // 移除品牌列表数据
    //  /admin/product/baseCategoryTrademark/remove/{category3Id}/{trademarkId}
    @ApiOperation("移除品牌列表数据")
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    public Result remove(@PathVariable Long category3Id,
                         @PathVariable Long trademarkId){
        //  调用服务层方法
        baseCategoryTrademarkService.remove(category3Id,trademarkId);
        //  返回数据
        return Result.ok();
    }
    // 保存品牌列表数据
    //  /admin/product/baseCategoryTrademark/save
    //  cagegory3Id trademarkIdList
    @ApiOperation("保存品牌列表数据")
    @PostMapping("/save")
    public Result save(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        //  调用方法
        baseCategoryTrademarkService.save(categoryTrademarkVo);
        return Result.ok();
    }
}
